<template>
  <el-dialog title="添加内转车"
             :visible.sync="dialogForm"
             width="1200px">
    <el-table :data="data"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection"></el-table-column>
      <el-table-column prop="plateNumber"
                       label="车牌号"></el-table-column>
      <el-table-column prop="carTeamName"
                       label="车队"></el-table-column>
    </el-table>
    <span slot="footer"
          class="dialog-footer">
      <el-button @click="dialogForm = false">取 消</el-button>
      <el-button class="ml-80"
                 type="primary"
                 @click="handleSubmit"
                 :loading="$store.getters.loadingBtn">保 存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { addInternalCarPool } from '@/api/accept/car'
import { getJobVehicleList } from '@/api/baseResource/baseResource'

export default {
  name: 'addCarForm',
  props:['jobPurpose'],
  data() {
    return {
      form: this.clearForm(),
      dialogForm: false,
      condition: {}, // 查询条件
      data: [], //table数组
      multipleSelection: []
    }
  },
  mounted() {
    //加载表格
    getJobVehicleList().then(res => {
      this.data = res.data.aaData
    })
  },
  methods: {
    clearForm() {
      return {}
    },
    //多选
    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    handleSubmit() {
      if (this.multipleSelection.length === 0) {
        this.$message({ message: '请至少选择一辆车!', type: 'error' })
      } else {
        let cars = []
        for (var i = 0; i < this.multipleSelection.length; i++) {
          cars.push({
            carNo: this.multipleSelection[i].plateNumber,
            carTeam: this.multipleSelection[i].carTeamName,
            remark: ''
          })
        }
        let param = {
          cars: cars,
          deptId: this.multipleSelection[0].orgId,
          deptName: this.multipleSelection[0].deptName,
          jobPurpose: this.jobPurpose,
          orgId: this.multipleSelection[0].orgId,
          orgName: this.multipleSelection[0].orgName
        }
        console.log('param',param)
        addInternalCarPool(param).then(res => {
          console.log('车', res)
          this.$message({type:'success',message:'添加成功'})
          this.$emit('load')
          this.dialogForm = false
        })
        
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
